#pragma once

#include<BWAPI.h>

using namespace BWAPI;

const int DELAY = 3;

float GetEdgeDistance(UnitType type1 , Position position1 , UnitType type2 , Position position2)
{
	float dx = 0.0;
	float dy = 0.0;
	const float top = position1.y() - type1.dimensionUp();
	const float bottom = position1.y() + type1.dimensionDown();
	const float anotherTop = position2.y() - type2.dimensionUp();
	const float anotherBottom = position2.y() + type2.dimensionDown();
	dy = top - anotherBottom;
	if(dy < 0.0)
	{
		dy = anotherTop - bottom;
		if(dy < 0.0)
		{
			dy = 0.0;
		}
	}

	const float left = position1.x() - type1.dimensionLeft();
	const float right = position1.x() + type1.dimensionRight();
	const float anotherLeft = position2.x() - type2.dimensionLeft();
	const float anotherRight = position2.x() + type2.dimensionRight();
	dx = left - anotherRight;
	if(dx < 0.0)
	{
		dx = anotherLeft - right;
		if(dx < 0.0)
		{
			dx = 0.0;
		}
	}

	return sqrt(dx * dx + dy * dy);
}

Position PredictFuturePosition(const Unit* unit , const int frameCount)
{
	Position answer(unit->getPosition());
	answer.x() += (int)(unit->getVelocityX() * (float)(frameCount+5));
	answer.y() += (int)(unit->getVelocityY() * (float)(frameCount+5));
	return answer;
}